//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ttjj.entity.navi;

import com.ttjj.common.Constants;
import com.ttjj.entity.map.Position;
import com.ttjj.enums.EnumDirection;
import com.ttjj.service.navigation.TerrainAnalyzer;

import java.util.ArrayList;
import java.util.List;

/**
 * 移动步
 */
public class TerrainStep {
    protected final Position pos;
    protected final TerrainStep lastStep;
    protected int stepDepth;
    protected int passByMudCost;
    protected int totalCost;

    public TerrainStep(Position pos, TerrainStep lastStep) {
        this.pos = pos;
        this.lastStep = lastStep;
        int len = Constants.getCommonLen();
        if (lastStep != null) {
            this.stepDepth = lastStep.getStepDepth() + len;
            this.passByMudCost = lastStep.getPassByMudCost();
            if (TerrainAnalyzer.isInMud(pos)) {
                this.passByMudCost += len;
            }
        }

        this.totalCost = this.stepDepth + this.passByMudCost;
    }

    public List<TerrainStep> getNextSteps() {
        List<TerrainStep> result = new ArrayList<>();
        if (this.pos.getX() > 0) {
            result.add(new TerrainStep(this.pos.stepByDirect(EnumDirection.TOP), this));
        }

        if (this.pos.getX() < 15) {
            result.add(new TerrainStep(this.pos.stepByDirect(EnumDirection.DOWN), this));
        }

        if (this.pos.getY() > 0) {
            result.add(new TerrainStep(this.pos.stepByDirect(EnumDirection.LEFT), this));
        }

        if (this.pos.getY() < 27) {
            result.add(new TerrainStep(this.pos.stepByDirect(EnumDirection.RIGHT), this));
        }

        return result;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        } else if (obj != null && this.getClass() == obj.getClass()) {
            TerrainStep other = (TerrainStep)obj;
            return this.pos.equals(other.pos);
        } else {
            return false;
        }
    }

    public int hashCode() {
        return this.pos.hashCode();
    }

    public Position getPos() {
        return this.pos;
    }

    public TerrainStep getLastStep() {
        return this.lastStep;
    }

    public int getStepDepth() {
        return this.stepDepth;
    }

    public int getPassByMudCost() {
        return this.passByMudCost;
    }

    public int getTotalCost() {
        return this.totalCost;
    }

    public void setStepDepth(int stepDepth) {
        this.stepDepth = stepDepth;
    }

    public void setPassByMudCost(int passByMudCost) {
        this.passByMudCost = passByMudCost;
    }

    public void setTotalCost(int totalCost) {
        this.totalCost = totalCost;
    }

    public String toString() {
        return "TerrainStep(pos=" + this.getPos() + ", lastStep=" + this.getLastStep() + ", stepDepth=" + this.getStepDepth() + ", passByMudCost=" + this.getPassByMudCost() + ", totalCost=" + this.getTotalCost() + ")";
    }
}
